<?php

class TypeRule extends Rule {

    const EMAIL = 'Email';
    const DATE_BR_FORMAT = 'Data DR';
    const DATE_BD_FORMAT = 'Data BD';
    const CEP = 'Cep';
    const PHONE = 'Telefone';
    const PHONE_WITH_DDD = 'Telefone com Ddd';
    const CPF = 'Cpf';
    const CNPJ = 'Cnpj';

    public function validate($ValueToValidate) {
        switch($this->Value) {
            case TypeRule::EMAIL:
                return $this->isEmpty($ValueToValidate) || Validation::Email($ValueToValidate);
            case TypeRule::DATE_BR_FORMAT:
                return $this->isEmpty($ValueToValidate) || Validation::Date($ValueToValidate);
            case TypeRule::DATE_BD_FORMAT:
                return $this->isEmpty($ValueToValidate) || Validation::Date($ValueToValidate, 'y-m-d');
            case TypeRule::CEP:
                return $this->isEmpty($ValueToValidate) || Validation::Cep($ValueToValidate);
            case TypeRule::PHONE:
                return $this->isEmpty($ValueToValidate) || Validation::Phone($ValueToValidate, false);
            case TypeRule::PHONE_WITH_DDD:
                return $this->isEmpty($ValueToValidate) || Validation::Phone($ValueToValidate, true);
            case TypeRule::CPF:
                return $this->isEmpty($ValueToValidate) || Validation::Cpf($ValueToValidate);
            case TypeRule::CNPJ:
                return $this->isEmpty($ValueToValidate) || Validation::Cnpj($ValueToValidate);
        }
        return false;
    }

    private function isEmpty($ValueToValidate) {
        return empty($ValueToValidate);
    }

    public function getMessage() {
        return 'O Campo "' . $this->FieldName . '" não possui um formato do tipo de "' . $this->Value . '"!';
    }

}

?>
